package com.m1.tzolkin.model.technos;

import com.m1.tzolkin.model.Action;
import com.m1.tzolkin.model.IAction;
import com.m1.tzolkin.model.board.ITZBoard;
import com.m1.tzolkin.model.exceptions.NoAvailableSkullException;
import com.m1.tzolkin.model.players.ITZPlayer;

public enum Technologies implements ITechnology {
	
	AGRICULTURE {
		public TechLevel[] getLevels() { return Agriculture.values(); }
		public IAction getLastAction() {
			return new Action() {
				/**
				 * 
				 */
				private static final long serialVersionUID = -1195367927725228850L;

				public void doAction(ITZBoard b, ITZPlayer p) {
					b.setUpTemples(1);
				}
			};
		}
	},
	RESOURCE_EXTRACTION {
		public TechLevel[] getLevels() { return ResourceExtraction.values(); }
		public IAction getLastAction() {
			return new Action() {
				/**
				 * 
				 */
				private static final long serialVersionUID = 4383958646522874341L;

				public void doAction(ITZBoard b, ITZPlayer p) {
					b.setCollectResource(2);
				}
			};
		}
	},
	ARCHITECTURE {
		public TechLevel[] getLevels() { return Architecture.values(); }
		public IAction getLastAction() {
			return new Action() {
				/**
				 * 
				 */
				private static final long serialVersionUID = -4213456648910480735L;

				public void doAction(ITZBoard b, ITZPlayer p) {
					p.addScore(3);
					b.getLog().addSentence(new String[] {
						p.getName(), "GET", "3", "POINTS"
					});
				}
			};
		}
	},
	THEOLOGY {
		public TechLevel[] getLevels() { return Theology.values(); }
		public IAction getLastAction() {
			return new Action() {
				/**
				 * 
				 */
				private static final long serialVersionUID = -9016950068480760516L;

				public void doAction(ITZBoard b, ITZPlayer p) {
					try {
						b.getBank().takeSkull();
						p.getWallet().addSkull();
						b.getLog().addSentence(new String[] {
							p.getName(), "GET", "1", "SKULL"
						});
					} catch (NoAvailableSkullException e) {
						// Rien
					}
				}
			};
		}
	};
	
	public enum Agriculture implements TechLevel {
		PLUSCORN, NOTILE_PLUSFISH, PLUSPLUSCORN;
	}
	
	public enum ResourceExtraction implements TechLevel {
		PLUSWOOD, PLUSROCK, PLUSGOLD;
	}
	
	public enum Architecture implements TechLevel {
		PLUSCORN_ONBUILD, PLUSSCORE_ONBUILD, LESSRESOURCE_ONBUILD;
	}
	
	public enum Theology implements TechLevel {
		NEXT_CIACTION, RESOURCE_TO_TEMPLE, PLUSSKULL;
	}
	
	public int getHeight() { return getLevels().length + 1; }
	public String getName() { return name(); }
	public abstract TechLevel[] getLevels();
	public abstract IAction getLastAction();
	
}
